/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package proj5labbd;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;

/*
 * Classe que herda de DBInterface apenas para dar alguns suportes a mais 
 * para o MainFrame do aplicativo
 */
public class DBMainInterface extends DBInterface {

    public DBMainInterface(DBConnector conn) {
        super(conn);
    }

    //Retorna a seleção total de uma tabela
    public String getAll(String table) throws SQLException {
            Statement stmt = conn.getConn().createStatement();
            ResultSet rs = stmt.executeQuery("SELECT * FROM "+table);
            String s = "";
            ResultSetMetaData meta = rs.getMetaData();
            while(rs.next()) {
                for ( int i = 1; i <= meta.getColumnCount(); i++ )
                    s += rs.getString(i) + " ";
                s += "\n";
            }
            return s;
    }

    //Executa uma DDL encontrada em algum script
    public void executeDDL( String script ) throws SQLException {
        Statement stmt = conn.getConn().createStatement();
        ResultSet rs = stmt.executeQuery(script);
    }

}
